<template>
    <rx-layout>
        <div slot="center">
            <a-tabs :default-active-key="'1'" v-if="beginShow">
                <a-tab-pane key="1" :tab="i18n('list.argsConf','参数配置')">
                    <SysPropertiesPanel
                        :configsJson="configsJson"
                        :siteSettingJson="siteSettingJson"
                        :osInst="osInst"
                        @updateSysConfig="updateSysConfig"
                        @updateOsInstConfig="updateOsInstConfig"
                        @saveProps="saveProps"
                    ></SysPropertiesPanel>
                </a-tab-pane>
                <a-tab-pane key="2" :tab="i18n('list.pwdConf','密码策略配置')">
                    <OsPasswordPolicyEdit></OsPasswordPolicyEdit>
                </a-tab-pane>
                <a-tab-pane key="3" :tab="i18n('list.webConf','网站配置')">
                    <SysSiteSettingEdit
                        :siteSettingJson="siteSettingJson"
                        @updateSitetting="updateSitetting"
                        @saveProps="saveProps"
                    ></SysSiteSettingEdit>
                </a-tab-pane>
                <a-tab-pane key="4" :tab="i18n('list.mailConf','邮件服务配置')">
                    <EmailValid></EmailValid>
                </a-tab-pane>
            </a-tabs>
        </div>
    </rx-layout>
</template>

<script>
import SysPropertiesPanel from './SysPropertiesPanel'
import OsPasswordPolicyEdit from '../../user/org/OsPasswordPolicyEdit'
import SysSiteSettingEdit from './SysSiteSettingEdit'
import userState from "@/assets/js/userState";
import SysPropertiesApi from "@/api/system/core/sysProperties";
import EmailValid from "@/views/modules/system/core/EmailValid";
import {Util} from "@lowcode/jpaas-common-lib";

export default {
    name: 'SysPropertiesPanelAndPassword',
    components: {
        SysPropertiesPanel,
        OsPasswordPolicyEdit,
        SysSiteSettingEdit,
        EmailValid
    },
    mixins:[userState],
    data() {
        return {
            text: '',
            configsJson:{
            },
            siteSettingJson:{
            },
            osInst:{
            },
            beginShow:false,
        }
    },
    created() {
        this.initData();
    },
    methods: {
        initData(){
            let self=this;
            SysPropertiesApi.getConfigMapByTenant().then(resp => {
                let data = resp.data;
                self.initSiteSetting(data);
                self.initConfigs(data);
                self.initOsInstConfigs(data);
            });
        },
        saveProps(){
            var self=this;
            let saveJson = {
                configs:this.configsJson,
                siteSetting:this.siteSettingJson,
                osInst:this.osInst
            }
            SysPropertiesApi.saveConfigMapByTenant(saveJson).then(res=>{
                Util.setKeyVal("paramsEncrypt",self.configsJson.paramsEncrypt || false);
            });
        },
        updateOsInstConfig(inst){
            this.osInst=inst;
        },
        updateSitetting(siteSetting){
            this.siteSettingJson=siteSetting;
        },
        updateSysConfig(config){
            this.siteSettingJson = config.siteSetting;
            //let ddd = JSON.parse(this.siteSettingJson.confs);
            this.configsJson = config.configs;
        },
        initSiteSetting(data){
            this.siteSettingJson=data.siteSetting;
        },
        initConfigs(data){
            this.configsJson=data.configs;
        },
        initOsInstConfigs(data){
            this.osInst=data.osInst;
            this.beginShow=true;
        },
        i18n(name,text,key){
            return this.$ti18(name,text,"SysConfig",key);
        }
    }
}
</script>

<style scoped>
</style>